package manager

import "strconv"

type Center struct {
	Name            string `toml:"name"`
	Host            string `toml:"host"`
	Port            int    `toml:"port"`
	Username        string `toml:"username"`
	RawPassword     string `toml:"password,omitempty"`
	EncodedPassword string `toml:"encodePassword,omitempty"`
	Password        `toml:",inline"`
}

func (c *Center) Addr() string {
	return c.Host + ":" + strconv.Itoa(c.Port)
}

func (c *Center) IsLocal() bool {
	return c.Host == "localhost" || c.Host == "127.0.0.1" || c.Host == "::1" || c.Host == ""
}

func (c *Center) Tidy() {
	if c.RawPassword != "" {
		c.Raw = c.RawPassword
		c.RawPassword = ""
	}
	if c.EncodedPassword != "" {
		c.Aes = c.EncodedPassword
		c.EncodedPassword = ""
	}
}
